<?php /* FORUMS $Id: addedit.php,v 1.26.6.2 2006/11/19 13:12:47 gregorerhardt Exp $ */
// Add / Edit forum

$forum_id = intval( dPgetParam( $_GET, 'forum_id', 0 ) );
$perms =& $AppUI->acl();

// check permissions for this record
$canAdd = $perms->checkModule( $m, 'add');
$canEdit = $perms->checkModuleItem( $m, 'edit', $forum_id );
if (!$canEdit || !$canAdd) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	echo $AppUI->getMsg();
	exit();
}

// load the companies class to retrieved denied projects
require_once( $AppUI->getModuleClass( 'projects' ) );

$forum_id = intval( dPgetParam( $_GET, 'forum_id', 0 ) );

//Pull forum information
$q =& new DBQuery;
$q->addTable('forums');
$q->addWhere("forums.forum_id = $forum_id");
$res = $q->exec();
echo db_error();
$forum_info = db_fetch_assoc( $res );

$status = isset( $forum_info['forum_status'] ) ? $forum_info['forum_status'] : -1;


// get any project records denied from viewing
$projObj = new CProject();

//Pull project Information
$q =& new DBQuery;
$q->addTable('projects');
$q->addQuery('project_id, project_name');
$q->addWhere('project_status <> 7');
$q->addOrder('project_name');
$projObj->setAllowedSQL($AppUI->user_id, $q);
if (isset($company_id))
	$q->addWhere("project_company = $company_id");
$projects = array( '0' => '' ) + $q->loadHashList();
echo db_error();

$perms =& $AppUI->acl();
$permittedUsers =& $perms->getPermittedUsers();
$users = array( '0' => '' ) + $permittedUsers;
?>
<form name="changeforum" action="?m=forums" method="post">
	<input type="hidden" name="dosql" value="do_forum_aed" />
	<input type="hidden" name="del" value="0" />
	<input type="hidden" name="forum_unique_update" value="<?=uniqid('')?>" />
	<input type="hidden" name="forum_id" value="<?=$forum_id?>" />

<table cellspacing="0" cellpadding="4" border="0" width="400px">
<tr>
	<th bgcolor="#E0E0E0" colspan="2"><?=$AppUI->_( $forum_id ? 'Edit' : 'Create' ).' '.$AppUI->_( 'Forum' )?></th>
</tr>
<tr>
	<td align="right" width="100"><?=$AppUI->_('Name')?></td>
	<td>
		<input type="text" class="text" style="width: 275px" name="forum_name" value="<?=@$forum_info['forum_name']?>" maxlength="50"/>
	</td>
</tr>
<tr>
	<td align="right"><?=$AppUI->_('Related Project')?></td>
	<td>
<?php
	echo arraySelect( $projects, 'forum_project', ' style="width: 280px" size="1" class="text"', $forum_info['forum_project'] );
?>
	</td>
</tr>
<tr>
	<td align="right"><?=$AppUI->_('Owner')?></td>
	<td>
<?php
	echo arraySelect( $users, 'forum_owner', ' style="width: 280px" size="1" class="text"', $forum_info['forum_owner'] ? $forum_info['forum_owner'] : $AppUI->user_id );
?>
	</td>
</tr>
<tr>
	<td align="right" nowrap><?=$AppUI->_('Moderator')?></td>
	<td>
<?php
	echo arraySelect( $users, 'forum_moderated', ' style="width: 280px" size="1" class="text"', $forum_info['forum_moderated'] );
?>
	</td>
</tr>
<?php if ($forum_id) { ?>
<tr>
	<td align="right"><?=$AppUI->_('Created On')?></td>
	<td><?=@$forum_info['forum_create_date']?></td>
</tr>
<tr>
	<td align="right"><?=$AppUI->_('Last Post')?></td>
	<td><?=@$forum_info['forum_last_date']?></td>
</tr>
<tr>
	<td align="right" nowrap><?=$AppUI->_('Message Count')?></td>
	<td><?=@$forum_info['forum_message_count']?></td>
</tr>
<?php } ?>
<tr>
	<td align="right" valign="top"><?=$AppUI->_('Description')?></td>
	<td>
		<textarea class="textarea" name="forum_description" rows="5" style="width: 275px;"><?=@$forum_info['forum_description']?></textarea>
	</td>
</tr>
<tr>
	<td align="center" colspan="2">
	<? if ($AppUI->user_id == 1 || $AppUI->user_id == $forum_info['forum_owner'] || $forum_id == 0) { ?>
		<input type="button" value="<?=$AppUI->_('Save')?>" class="button" onclick="doSaveForum()" />
	<? } ?>
		<input type="button" value="<?=$AppUI->_('Cancel')?>" class="button" onclick="$('idGlass').onclick()"/>
	</td>
</tr>
</table>
</form>
